package com.financing.platform.web.api;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.zip.ZipOutputStream;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.jpush.api.utils.Base64;

import com.financing.platform.common.Pager;
import com.financing.platform.common.ResultCode;
import com.financing.platform.common.ResultMap;
import com.financing.platform.common.ResultMap.STATUS;
import com.financing.platform.dao.impl.JpushMessageDaoImpl;
import com.financing.platform.dto.AccessInfoDTO;
import com.financing.platform.dto.CompanyInvitationCodeDTO;
import com.financing.platform.dto.FaUserAuthDTO;
import com.financing.platform.dto.FaUserCertDTO;
import com.financing.platform.dto.FaUserDTO;
import com.financing.platform.dto.MessageJpushDTO;
import com.financing.platform.dto.MessageJpushUserPhoneAliasDTO;
import com.financing.platform.dto.UserInfoDTO;
import com.financing.platform.service.ICompanyService;
import com.financing.platform.service.IFaUserAuthService;
import com.financing.platform.service.IFaUserService;
import com.financing.platform.service.impl.FaUserVisitServiceImpl;
import com.financing.platform.util.CsvExportUtil;
import com.financing.platform.util.DTOdateSet;
import com.financing.platform.util.PropertiesUtils;
import com.financing.platform.util.DateUtil;
import com.financing.platform.vo.FaUserVO;
import com.financing.platform.vo.FaUserVisitStatisticVO;

@Controller("faUserActionApi")
@RequestMapping("/api/fa")
@Scope("prototype")
public class FAUserAction extends BaseAction{

	@Autowired
	IFaUserService faUserServiceImpl;
	
	@Autowired
	IFaUserAuthService faUserAuthServiceImpl;
	
	@Autowired
	ICompanyService companyServiceImpl;

	@Autowired
	FaUserVisitServiceImpl faUserVisitServiceImpl;
	
	@Autowired
	JpushMessageDaoImpl jpushMessageDaoImpl;
	
	@SuppressWarnings("unchecked")
	@RequestMapping("/queryFaUserList.shtml")
	@ResponseBody
	public ResultMap queryFaUserList(HttpServletRequest request,
			HttpServletResponse response,FaUserDTO faUserDTO,Pager pager,String adviserUserId) {
		try{
			log.info("Begin query fa user list!");

			//参数过滤
			if(StringUtils.isNotBlank(faUserDTO.getActSource()) && faUserDTO.getActSource().indexOf("请选择")>=0){
				faUserDTO.setActSource(null);
			}

			if(!StringUtils.isBlank(faUserDTO.getSystemUserId()) && ("isnoManagerUser").equals(faUserDTO.getSystemUserId())){
				faUserDTO.setSystemUserId(null);
			}else{
				if(StringUtils.isBlank(adviserUserId)){
					List<String> systemUserIds = faUserServiceImpl.queryFaUserSubUserId(faUserDTO.getSystemUserId());
					systemUserIds.add(faUserDTO.getSystemUserId());
					faUserDTO.setSystemUserIds(systemUserIds);
				}else{
					List<String> systemUserIds = new ArrayList<String>();
					systemUserIds.add(adviserUserId);
					faUserDTO.setSystemUserIds(systemUserIds);
				}
			}
			// 判断当前登录者是否是理财师管理员
			HttpSession session = request.getSession();
			UserInfoDTO user = (UserInfoDTO)session.getAttribute(DTOdateSet.user);
			
			if(!"admin".equals(user.getUserNickname())){
				boolean isManager = false;
				List<AccessInfoDTO> accessInfoList = user.getAccessList();
				for(AccessInfoDTO access : accessInfoList){
					if(access.getActionName().equals("addManagerLicaishiUser.shtml")){
						isManager = true;
						break;
					}
				}
				if(!isManager){
					faUserDTO.setSystemUserId(user.getUserId());
				}
			}
			
			faUserDTO.setBegin(pager.getStartIndex());
			faUserDTO.setPageSize(pager.getPageSize());
			
			int count = faUserServiceImpl.queryAllFaUserInfoCount(faUserDTO);
			pager.setTotalCount(count);
			
			List<FaUserDTO> list;
			Future future = null;
			if(count>0){
				list = faUserServiceImpl.queryAllFaUserInfo(faUserDTO);
			}else{
				list = Collections.EMPTY_LIST;
			}

			resultMap.setAttribute("list",list);
			resultMap.setAttribute("pager",pager);
			resultMap.setStatus(STATUS.SUCCESS);
			resultMap.setStatusCode(ResultCode.RESULT_CODE_SUCCESS);
			
			log.info("End query fa user list!");
		}catch(Exception e){
			log.error("queryFaUserList error !",e);
			resultMap.setStatus(STATUS.FAILE);
			resultMap.setStatusCode(ResultCode.RESULT_CODE_SYSTEM_ERROR);
		}
			
			
			return resultMap;
	}
	
	@RequestMapping("/queryFaUser.shtml")
	@ResponseBody
	public ResultMap queryFaUser(HttpServletRequest request,
			HttpServletResponse response,FaUserDTO faUserDTO) {
		
		try{
			 log.info("Begin query fa user!");
			    
			 //参数缺失
			 if(faUserDTO.getId() == null){
			    resultMap.setStatus(STATUS.SUCCESS);
				resultMap.setStatusCode(ResultCode.STATUS_CODE_PARAMETERS_LOSE);
				return resultMap;
			 }
			    //查询FA信息
			    faUserDTO = faUserServiceImpl.queryFaUserInfoView(faUserDTO);
			    
			    FaUserAuthDTO faUserAuthDTO = new FaUserAuthDTO();
			    faUserAuthDTO.setFaId(faUserDTO.getId());
			    
			    //查询FA证书信息
			    List<FaUserAuthDTO> faUserAuthList = faUserAuthServiceImpl.queryFaUserAuthList(faUserAuthDTO);
			    
			    FaUserCertDTO faUserCertDTO = new FaUserCertDTO();
			    faUserCertDTO.setFaId(faUserDTO.getId());
			    
			    List<FaUserCertDTO> faUserCertList = faUserAuthServiceImpl.queryFaUserCertList(faUserCertDTO);
			    faUserDTO.setuPassWord(null);
			    resultMap.setAttribute("faUserInfo", faUserDTO);
			    resultMap.setAttribute("faUserAuthList", faUserAuthList);
			    resultMap.setAttribute("faUserCertList", faUserCertList);
			    resultMap.setStatus(STATUS.SUCCESS);
				resultMap.setStatusCode(ResultCode.RESULT_CODE_SUCCESS);
			    log.info("End query fa user !");
		}catch(Exception e){
			log.error("query fa user info error!",e);
			resultMap.setStatus(STATUS.FAILE);
			resultMap.setStatusCode(ResultCode.RESULT_CODE_SYSTEM_ERROR);
		}
		   
			return resultMap;
	}
	
	@RequestMapping("/queryShopFaUser.shtml")
	@ResponseBody
	public ResultMap queryShopFaUser(HttpServletRequest request,
			HttpServletResponse response,FaUserDTO faUserDTO) {
		
		try{
			 log.info("Begin query fa user!");
			    
			 //参数缺失
			 if(faUserDTO.getId() == null){
			    resultMap.setStatus(STATUS.SUCCESS);
				resultMap.setStatusCode(ResultCode.STATUS_CODE_PARAMETERS_LOSE);
				return resultMap;
			 }
			 
			 faUserDTO =faUserServiceImpl.queryFaUserInfo(faUserDTO);
			 
			 FaUserDTO p = new FaUserDTO();
			 p.setuLoginName(faUserDTO.getuLoginName());
			 
			    //查询FA信息
			    faUserDTO = faUserServiceImpl.queryAllShopFaUserInfo(p).get(0);
			    
			    faUserDTO.setuPassWord(null);
			    resultMap.setAttribute("faUserInfo", faUserDTO);
			    resultMap.setStatus(STATUS.SUCCESS);
				resultMap.setStatusCode(ResultCode.RESULT_CODE_SUCCESS);
			    log.info("End query fa user !");
		}catch(Exception e){
			log.error("query fa user info error!",e);
			resultMap.setStatus(STATUS.FAILE);
			resultMap.setStatusCode(ResultCode.RESULT_CODE_SYSTEM_ERROR);
		}
		   
			return resultMap;
	}
	
	@RequestMapping("/queryFaUserForAudit.shtml")
	@ResponseBody
	public ResultMap queryFaUserForAudit(HttpServletRequest request,
			HttpServletResponse response,FaUserDTO faUserDTO) {
		
		try{
			 log.info("Begin query fa user For Audit!");
			 
			 //参数缺失
			 if(faUserDTO.getId() == null){
			    resultMap.setStatus(STATUS.SUCCESS);
				resultMap.setStatusCode(ResultCode.STATUS_CODE_PARAMETERS_LOSE);
				return resultMap;
			 }
			    //查询FA信息
			    faUserDTO = faUserServiceImpl.queryFaUserInfo(faUserDTO);
			    faUserDTO.setuPassWord(null);
			    resultMap.setAttribute("faUserInfo", faUserDTO);
			    resultMap.setStatus(STATUS.SUCCESS);
				resultMap.setStatusCode(ResultCode.RESULT_CODE_SUCCESS);
			log.info("End query fa user For Audit!");
		}catch(Exception e){
			log.error("Begin query fa user For Audit error!",e);
			resultMap.setStatus(STATUS.FAILE);
			resultMap.setStatusCode(ResultCode.RESULT_CODE_SYSTEM_ERROR);
		}
		   
			return resultMap;
	}
	
	
	/**
	 * 用户认证审核
	 * @param request
	 * @param response
	 * @param faUserDTO
	 * @return
	 */
	@RequestMapping("/updateFaUserForAudit.shtml")
	@ResponseBody
	public synchronized ResultMap updateFaUserForAudit(HttpServletRequest request,
			HttpServletResponse response,FaUserDTO faUserDTO) {
		try{
			log.info("Begin updateFaUserForAudit !");
			 //参数缺失
			 if(faUserDTO.getId() == null){
			    resultMap.setStatus(STATUS.SUCCESS);
				resultMap.setStatusCode(ResultCode.STATUS_CODE_PARAMETERS_LOSE);
				return resultMap;
			 }
			 
			DTOdateSet.setUpdateInfo(faUserDTO, request.getSession());
			
			faUserServiceImpl.updateFaUserInfo(faUserDTO);
			
			//审核完成 - 极光推送消息到app端
//			String content = "";
//			if(StringUtils.equals(faUserDTO.getuShopRole(), "99")) {
//				content = "您的身份认证失败，您可以重新申请认证！";
//			} else if(StringUtils.equals(faUserDTO.getuShopRole(), "2")) {
//				content = "您的身份认证成功！";
//			}
//
//			if(StringUtils.isNotBlank(content)) {
//				List<MessageJpushUserPhoneAliasDTO> phoneAliasList = jpushMessageDaoImpl.queryJpushUserPhonealias(faUserDTO.getId());
//				if(CollectionUtils.isNotEmpty(phoneAliasList)){
//					MessageJpushUserPhoneAliasDTO phoneAlias = phoneAliasList.get(0);
//					
//					MessageJpushDTO messageJpushDTO = new MessageJpushDTO();
//	
//					messageJpushDTO.setFpJpushMsgRec(phoneAlias.getFpJpushAliasShop());
//					messageJpushDTO.setFpJpushTitle("理财师店铺");
//					messageJpushDTO.setFpJpushContent(content);
//					messageJpushDTO.setFpJpushRedrict("");
//					messageJpushDTO.setFpJpushMsgType("04");// 消息类型 01:系统消息 02:运营推送 04:理财师认证
//					messageJpushDTO.setFpJpushSendType("01");// 推送消息类型  01:实时推送  02:定时推送
//					messageJpushDTO.setCreateBy("");
//					messageJpushDTO.setCreateDate(new Date());
//					messageJpushDTO.setUpdateBy("");
//					messageJpushDTO.setUpdateDate(new Date());
//					messageJpushDTO.setFpJpushSource("shop"); //加店铺标识
//					jpushMessageDaoImpl.addJpushMessage(messageJpushDTO);
//				}
//			}
			
		    resultMap.setStatus(STATUS.SUCCESS);
			resultMap.setStatusCode(ResultCode.RESULT_CODE_SUCCESS);
			log.info("End updateFaUserForAudit !");
		}catch(Exception e){
			e.printStackTrace();
			log.error("update updateFaUserForAudit error!",e);
			resultMap.setStatus(STATUS.FAILE);
			resultMap.setStatusCode(ResultCode.RESULT_CODE_SYSTEM_ERROR);
		}
			
			return resultMap;
	}
	
	/**
	 * 理财师工具用户认证审核
	 * @param request
	 * @param response
	 * @param faUserDTO
	 * @return
	 */
	@RequestMapping("/updateShopFaUserForAudit.shtml")
	@ResponseBody
	public synchronized ResultMap updateShopFaUserForAudit(HttpServletRequest request,
			HttpServletResponse response,FaUserDTO faUserDTO) {
		try{
			log.info("Begin updateFaUserForAudit !");
			 //参数缺失
			 if(faUserDTO.getId() == null){
			    resultMap.setStatus(STATUS.SUCCESS);
				resultMap.setStatusCode(ResultCode.STATUS_CODE_PARAMETERS_LOSE);
				return resultMap;
			 }
			 
			DTOdateSet.setUpdateInfo(faUserDTO, request.getSession());
			
			FaUserDTO p = new FaUserDTO();
			p.setId(faUserDTO.getId());
			p.setuShopRole(faUserDTO.getuShopRole());
			
			//审核完成 - 极光推送消息到app端
			String content = "";
			if(StringUtils.equals(faUserDTO.getuShopRole(), "99")) {
				content = "您的身份认证失败，您可以重新申请认证！";
			} else if(StringUtils.equals(faUserDTO.getuShopRole(), "2")) {
				content = "您的身份认证成功！";
				p.setAuthDate(new Date());
			}
			
			//理财师金策师审核合并  新增
			p.setuRole(faUserDTO.getuShopRole());
			DTOdateSet.setUpdateInfo(p, request.getSession());
			faUserServiceImpl.updateFaUserInfoShop(p);
			
			

			if(StringUtils.isNotBlank(content)) {
				List<MessageJpushUserPhoneAliasDTO> phoneAliasList = jpushMessageDaoImpl.queryJpushUserPhonealias(faUserDTO.getId());
				if(CollectionUtils.isNotEmpty(phoneAliasList)){
					MessageJpushUserPhoneAliasDTO phoneAlias = phoneAliasList.get(0);
					
					MessageJpushDTO messageJpushDTO = new MessageJpushDTO();
	
					messageJpushDTO.setFpJpushMsgRec(phoneAlias.getFpJpushAliasShop());
					messageJpushDTO.setFpJpushTitle("金策师");
					messageJpushDTO.setFpJpushContent(content);
					messageJpushDTO.setFpJpushRedrict("");
					messageJpushDTO.setFpJpushMsgType("04");// 消息类型 01:系统消息 02:运营推送 04:理财师认证
					messageJpushDTO.setFpJpushSendType("01");// 推送消息类型  01:实时推送  02:定时推送
					messageJpushDTO.setCreateBy("");
					messageJpushDTO.setCreateDate(new Date());
					messageJpushDTO.setUpdateBy("");
					messageJpushDTO.setUpdateDate(new Date());
					messageJpushDTO.setFpJpushSource("shop"); //加店铺标识
					jpushMessageDaoImpl.addJpushMessage(messageJpushDTO);
				}
			}
			
		    resultMap.setStatus(STATUS.SUCCESS);
			resultMap.setStatusCode(ResultCode.RESULT_CODE_SUCCESS);
			log.info("End updateFaUserForAudit !");
		}catch(Exception e){
			e.printStackTrace();
			log.error("update updateFaUserForAudit error!",e);
			resultMap.setStatus(STATUS.FAILE);
			resultMap.setStatusCode(ResultCode.RESULT_CODE_SYSTEM_ERROR);
		}
			
			return resultMap;
	}
	
	/**
	 * 查询审核信息
	 * @param request
	 * @param response
	 * @param faUserDTO
	 * @return
	 */
	@RequestMapping("/updateFaUserForVisit.shtml")
	@ResponseBody
	public synchronized ResultMap updateFaUserForVisit(HttpServletRequest request,
			HttpServletResponse response,FaUserDTO faUserDTO) {
		try{
			log.info("Begin updateFaUserForAudit !");
			Map<String, Object>  map = getParameterMap(request);	
			DTOdateSet.setUpdateInfo(faUserDTO, request.getSession());
			DTOdateSet.setCreateInfo(faUserDTO, request.getSession());
			map.put("updateBy", faUserDTO.getUpdateBy());
			map.put("createBy", faUserDTO.getCreateBy());
			faUserServiceImpl.updateFaUserForVisit(map);
			
		    resultMap.setStatus(STATUS.SUCCESS);
			resultMap.setStatusCode(ResultCode.RESULT_CODE_SUCCESS);
			log.info("End updateFaUserForAudit !");
		}catch(Exception e){
			log.error("update updateFaUserForAudit error!",e);
			resultMap.setStatus(STATUS.FAILE);
			resultMap.setStatusCode(ResultCode.RESULT_CODE_SYSTEM_ERROR);
		}
			
			return resultMap;
	}
	/**提交审核
	 * @param request
	 * @param response
	 * @param faUserDTO
	 * @return
	 */
	@RequestMapping("/updateFaUser.shtml")
	@ResponseBody
	public synchronized ResultMap updateFaUser(HttpServletRequest request,
			HttpServletResponse response,FaUserDTO faUserDTO) {
		try{
			log.info("Begin update fa user info !");
			
			DTOdateSet.setUpdateInfo(faUserDTO, request.getSession());
			
			faUserServiceImpl.updateFaUserInfo(faUserDTO);
			
		    resultMap.setStatus(STATUS.SUCCESS);
			resultMap.setStatusCode(ResultCode.RESULT_CODE_SUCCESS);
			log.info("End update fa user info !");
		}catch(Exception e){
			log.error("update fa user info error!",e);
			resultMap.setStatus(STATUS.FAILE);
			resultMap.setStatusCode(ResultCode.RESULT_CODE_SYSTEM_ERROR);
		}
			
			return resultMap;
	}

	@RequestMapping("/updateFaUserCert.shtml")
	@ResponseBody
	public synchronized ResultMap updateFaUserCert(HttpServletRequest request,
			HttpServletResponse response,String id ,String uCardAddress) {
		try{
			log.info("Begin update fa user cert !");
			
			
			if(id == null){
				resultMap.setStatus(STATUS.SUCCESS);
				resultMap.setStatusCode(ResultCode.STATUS_CODE_PARAMETERS_LOSE);
				return resultMap;
			}
			
			FaUserDTO faUserDTOTmp = new FaUserDTO();
			faUserDTOTmp.setId(id);
			faUserDTOTmp.setuCardAddress(uCardAddress);
			
			//上传名片修改为审核中
			faUserDTOTmp.setuRole("98");
			faUserDTOTmp.setAddAuthDate(DateUtil.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss"));
			
			faUserServiceImpl.updateFaUserInfo(faUserDTOTmp);
			
		    resultMap.setStatus(STATUS.SUCCESS);
			resultMap.setStatusCode(ResultCode.RESULT_CODE_SUCCESS);
			log.info("End update fa user cert !");
		}catch(Exception e){
			log.error("update fa user cert error!",e);
			resultMap.setStatus(STATUS.FAILE);
			resultMap.setStatusCode(ResultCode.RESULT_CODE_SYSTEM_ERROR);
		}
			
			return resultMap;
	}
	
	/**查询 用户邀请人数及认证通过的
	 * @param request
	 * @param response
	 * @param faUserDTO
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping("/queryFaUserListAuthPass.shtml")
	@ResponseBody
	public ResultMap queryFaUserListAuthPass(HttpServletRequest request,
			HttpServletResponse response,FaUserDTO faUserDTO,Pager pager) {
		try{
			log.info("in queryFaUserListAuthPass degin !");
			
			faUserDTO.setBegin(pager.getStartIndex());
			faUserDTO.setPageSize(pager.getPageSize());
			
			int count = faUserServiceImpl.queryFaUserListAuthPassCount(faUserDTO);
			pager.setTotalCount(count);
			
			List<FaUserVO> list;
			if(count>0){
				list = faUserServiceImpl.queryFaUserListAuthPass(faUserDTO);
			}else{
				list = Collections.EMPTY_LIST;
			}
			
			resultMap.setAttribute("list",list);
			resultMap.setAttribute("pager",pager);
			
		    resultMap.setStatus(STATUS.SUCCESS);
			resultMap.setStatusCode(ResultCode.RESULT_CODE_SUCCESS);
			log.info("End update fa user info !");
		}catch(Exception e){
			log.error("update fa user info error!",e);
			resultMap.setStatus(STATUS.FAILE);
			resultMap.setStatusCode(ResultCode.RESULT_CODE_SYSTEM_ERROR);
		}
			
			return resultMap;
	}
	/**查询 单个用户邀请人及认证通过的
	 * @param request
	 * @param response
	 * @param faUserDTO
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping("/querySingleFaUserListAuthPass.shtml")
	@ResponseBody
	public ResultMap querySingleFaUserListAuthPass(HttpServletRequest request,
			HttpServletResponse response,FaUserDTO faUserDTO,Pager pager) {
		try{
			log.info("in querySingleFaUserListAuthPass degin !");
			//参数缺失
			 if(faUserDTO.getSourceCode() == null){
			    resultMap.setStatus(STATUS.SUCCESS);
				resultMap.setStatusCode(ResultCode.STATUS_CODE_PARAMETERS_LOSE);
				return resultMap;
			 }
			faUserDTO.setBegin(pager.getStartIndex());
			faUserDTO.setPageSize(pager.getPageSize());
			
			int count = faUserServiceImpl.querySingleFaUserListAuthPassCount(faUserDTO);
			pager.setTotalCount(count);
			
			List<FaUserDTO> list;
			if(count>0){
				list = faUserServiceImpl.querySingleFaUserListAuthPass(faUserDTO);
			}else{
				list = Collections.EMPTY_LIST;
			}
			
			resultMap.setAttribute("list",list);
			resultMap.setAttribute("pager",pager);
			
		    resultMap.setStatus(STATUS.SUCCESS);
			resultMap.setStatusCode(ResultCode.RESULT_CODE_SUCCESS);
			log.info("in querySingleFaUserListAuthPass end!");
		}catch(Exception e){
			log.error("in querySingleFaUserListAuthPass error!",e);
			resultMap.setStatus(STATUS.FAILE);
			resultMap.setStatusCode(ResultCode.RESULT_CODE_SYSTEM_ERROR);
		}
			
			return resultMap;
	}
	@SuppressWarnings({ "unchecked", "rawtypes" })
	@RequestMapping("/faUserCsv.shtml")
	public void queryFaUserListCsv(HttpServletRequest request,
            HttpServletResponse response,FaUserDTO faUserDTO) {
		
		log.info("in faUserCsv begin!");
		
		ZipOutputStream zos = null;
		List list = null;
        try{
            log.info("Begin faUserCsv list!");
            faUserDTO.setPageSize(5000);
            int count = faUserServiceImpl.queryAllFaUserInfoCount(faUserDTO);
            
            //如果查询总数量 《= PageSize，直接生成CSV
            if(count <= faUserDTO.getPageSize()){
            	log.info("Begin faUserCsv list《=!"+count+":"+faUserDTO.getPageSize());
            	 list = faUserServiceImpl.queryAllFaUserInfo(faUserDTO);
                 CsvExportUtil.doCsvExport(response, list);
                 return ;
            }
            
            //如果查询总数量  > PageSize， 打成zip
            response.reset();
            response.setHeader("Content-Disposition",
                    "attachment;filename=faUserExport.zip");
            zos = new ZipOutputStream(response.getOutputStream());
            int i = 1;
            do {
            	faUserDTO.setPageNo(i++);
                list = faUserServiceImpl.queryAllFaUserInfo(faUserDTO);
                CsvExportUtil.doCsvExportForZip(zos, list,"faUser"+faUserDTO.getBegin()+"-"+(faUserDTO.getEnd()+faUserDTO.getBegin())+".csv");
			} while (list.size() == faUserDTO.getPageSize());
            
            zos.closeEntry();
            zos.finish();
            log.info("in faUserCsv End!");
        }catch(Exception e){
            log.error("faUserCsv error !",e);
        }finally {
			if (zos != null) {
				try {
					zos.close();
				} catch (IOException e) {
				}
			}
		}

        return;
    }
	@SuppressWarnings({ "unchecked", "rawtypes" })
	@RequestMapping("/faUserAuthPassCsv.shtml")
	public void queryFaUserAuthPassCsv(HttpServletRequest request,
			HttpServletResponse response,FaUserDTO faUserDTO) {
		try{
			log.info("Begin faUserAuthPassCsv list!");
			
				List list = faUserServiceImpl.queryFaUserListAuthPass(faUserDTO);
				CsvExportUtil.doCsvExport(response, list);
				
			log.info("End faUserAuthPassCsv list!");
		}catch(Exception e){
			log.error("faUserAuthPassCsv error !",e);
		}
			
			
		return;
	}
	
	/**
	 * 
	 * @Title: makeCompanyUser
	 * @Description: 标记用户为机构总账户 
	 * @param @param request
	 * @param @param response
	 * @param @param faUserDTO
	 * @param @return   
	 * @return String   
	 * @throws
	 */
	@RequestMapping("/makeCompanyUser.shtml")
	@ResponseBody
	public ResultMap makeCompanyUser(HttpServletRequest request,
			HttpServletResponse response,CompanyInvitationCodeDTO cic){
		try{
			DTOdateSet.setCreateInfo(cic, request.getSession());
			DTOdateSet.setUpdateInfo(cic, request.getSession());
			resultMap.setAttribute("cic", companyServiceImpl.makeCompanyUser(cic));
			resultMap.setStatus(STATUS.SUCCESS);
			resultMap.setStatusCode(ResultCode.RESULT_CODE_SUCCESS);
			log.info("in querySingleFaUserListAuthPass end!");
		}catch(Exception e){
			log.error("in querySingleFaUserListAuthPass error!",e);
			resultMap.setStatus(STATUS.FAILE);
			resultMap.setStatusCode(ResultCode.RESULT_CODE_SYSTEM_ERROR);
		}
		return resultMap;
	}
	
	/**
	 * 从request中获得参数Map，并返回可读的Map
	 * @param request
	 * @return
	 */
	@SuppressWarnings({ "rawtypes" })
	public  Map<String, Object> getParameterMap(HttpServletRequest request) {
	    // 参数Map
	    Map properties = request.getParameterMap();
	    // 返回值Map
	    Map<String,Object> returnMap = new HashMap<String,Object> ();
	    Iterator entries = properties.entrySet().iterator();
	    Map.Entry entry;
	    String name = "";
	    String value = "";
	    while (entries.hasNext()) {
	        entry = (Map.Entry) entries.next();
	        name = (String) entry.getKey();
	        Object valueObj = entry.getValue();
	        if(null == valueObj){
	            value = "";
	        }else if(valueObj instanceof String[]){
	            String[] values = (String[])valueObj;
	            for(int i=0;i<values.length;i++){
	                value = values[i] + ",";
	            }
	            value = value.substring(0, value.length()-1);
	        }else{
	            value = valueObj.toString();
	        }
	        returnMap.put(name, value);
	    }
	    return returnMap;
	}

	/**
	 *
	 * @Title: 获取 活动来源集合
	 * @throws
	 */
	@RequestMapping("/queryActSource.shtml")
	@ResponseBody
	public ResultMap queryActSource(HttpServletRequest request,
									 HttpServletResponse response){
		try{
			List<String> list = faUserServiceImpl.queryActSource();
			list.add(0,"-请选择-");
			resultMap.setAttribute("list", list);
			resultMap.setStatus(STATUS.SUCCESS);
			resultMap.setStatusCode(ResultCode.RESULT_CODE_SUCCESS);
			log.info("in querySingleFaUserListAuthPass end!");
		}catch(Exception e){
			log.error("in querySingleFaUserListAuthPass error!",e);
			resultMap.setStatus(STATUS.FAILE);
			resultMap.setStatusCode(ResultCode.RESULT_CODE_SYSTEM_ERROR);
		}
		return resultMap;
	}
}